<style lang="less" scoped>
.report-audit {
  width: 100%;
  height: 100%;
  /deep/.el-table__inner-wrapper {
    height: 100% !important;
  }
  .shaixuan {
    display: flex;
    align-items: center;
    justify-content: end;
    background: #fff;
    padding: 5px;
    img {
      height: 20px;
    }
  }
  .pagination-css {
    padding: 5px;
    box-sizing: border-box;
    background-color: #fff;
    display: flex;
    justify-content: right;
    margin-top: 5px;
  }
}
</style>

<template>
  <div class="report-audit">
    <el-form :model="ruleform" inline class="form-css">
      <el-form-item label="项目类型：">
        <el-select
          v-model="ruleform.projectType"
          class="m-2"
          placeholder=""
          style="width: 200px"
        >
          <el-option
            v-for="(item, index) in typeList"
            :key="index"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="报告时间：">
        <el-date-picker
          v-model="ruleform.reportTime"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
          style="width: 200px"
        />
      </el-form-item>
      <!-- <el-form-item label="报告状态：">
        <el-select v-model="ruleform.reportType" class="m-2" placeholder="" style="width: 200px;">
            <el-option
              v-for="(item, index) in reportList"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="省份：">
        <el-select v-model="ruleform.province" class="m-2" placeholder="" style="width: 200px;">
            <el-option
              v-for="(item, index) in provinceList"
              :key="index"
              :label="item.label"
              :value="item.label"
            />
          </el-select>
      </el-form-item> -->
      <el-form-item label="销售：">
        <el-input
          v-model="ruleform.sellName"
          placeholder=""
          style="width: 200px"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="项目点范围：">
        <el-select v-model="ruleform.projectPoint" class="m-2" placeholder="" style="width: 200px;">
          <el-option
            v-for="(item, index) in projectList"
            :key="index"
            :label="item.label"
            :value="item.label"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item label="项目点：">
        <el-select
          v-model="ruleform.projectPoint"
          placeholder="请输入项目点名称"
          filterable
        >
          <el-option
            v-for="(item, index) in organNameList"
            :key="index"
            :label="item"
            :value="item"
          />
        </el-select>
        <!-- <el-cascader v-model="ruleform.projectPoint" :props="hosProps" filterable  /> -->
      </el-form-item>
      <!-- <el-form-item label="审核机构范围：">
        <el-cascader v-model="ruleform.auditHospital" :props="auditProps" filterable  />
      </el-form-item> -->
      <el-form-item label="">
        <el-button type="primary" @click="search"
          ><el-icon style="margin-right: 6px"><Search /></el-icon>
          搜索</el-button
        >
        <el-button @click="reset"
          ><el-icon style="margin-right: 6px"><Refresh /></el-icon>
          重置</el-button
        >
        <vue3-json-excel
          :fields="json_fields"
          :name="userExcelName"
          :fetch="downloadEx"
          style="margin-left: 12px"
        >
          <el-button>
            <!-- <el-icon style="margin-right: 6px"><Document /></el-icon> -->
            <img
              style="margin-right: 6px; width: 12px"
              src="@/images/daochu.png"
              alt=""
            />

            导出</el-button
          >
        </vue3-json-excel>
        <!-- <el-button type="primary"><el-icon><Document /></el-icon>导出</el-button> -->
      </el-form-item>
    </el-form>
    <div class="filter-column">
      <el-popover
        placement="bottom"
        title="筛选条件"
        :width="150"
        trigger="click"
      >
        <el-checkbox-group v-model="filtrateList" @change="changeBox">
          <el-checkbox label="project">项目类型</el-checkbox>
          <el-checkbox label="t_sn">条码</el-checkbox>
          <el-checkbox label="insname">项目点名称</el-checkbox>
          <el-checkbox label="name">姓名</el-checkbox>
          <el-checkbox label="sex">性别</el-checkbox>
          <el-checkbox label="age">年龄</el-checkbox>
          <el-checkbox label="auditstatus">报告状态</el-checkbox>
          <el-checkbox label="devname">设备名称</el-checkbox>
          <el-checkbox label="checkTime">检查时间</el-checkbox>
          <el-checkbox label="docname">检查医师</el-checkbox>
          <el-checkbox label="uploadTime">上传时间</el-checkbox>
          <el-checkbox label="analyseDoc">分析医师</el-checkbox>
          <el-checkbox label="reportTime">报告时间</el-checkbox>
          <el-checkbox label="reviewTime">质控时间</el-checkbox>
          <el-checkbox label="mrid">病历记录ID</el-checkbox>
          <el-checkbox label="devid">设备SN</el-checkbox>
          <el-checkbox label="addr">销售省份</el-checkbox>
          <el-checkbox label="uname">销售姓名</el-checkbox>
        </el-checkbox-group>
        <template #reference>
          <el-button type="text"
            ><div class="shaixuan">
              <img src="@/images/shaixuan.png" alt="" /> 筛选列
            </div></el-button
          >
        </template>
      </el-popover>
    </div>
    <el-table
      v-loading="tableLoading"
      :data="tableData"
      :header-cell-style="{ backgroundColor: '#EEF6FF' }"
      stripe
      border
      height="calc(100% - 224px)"
      style="width: 100%; padding: 10px"
    >
      <el-table-column type="index" width="50" align="center" />
      <el-table-column
        v-if="filtrateList.includes('project')"
        prop="project"
        min-width="81px"
        label="项目类型"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('t_sn')"
        prop="t_sn"
        min-width="120px"
        label="条码"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('insname')"
        prop="insname"
        min-width="120px"
        label="项目点名称"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('name')"
        prop="name"
        min-width="80px"
        label="姓名"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('sex')"
        prop="sex"
        min-width="80px"
        label="性别"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('age')"
        prop="age"
        min-width="80px"
        label="年龄"
        align="center"
        show-overflow-tooltip
          >
        <template #default="{ row }">
          <span>{{ row.age == 0 ? "-" : row.age }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="filtrateList.includes('tel')"
        prop="tel"
        min-width="80px"
        label="电话"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('auditstatus')"
        prop="auditstatus"
        min-width="84px"
        label="报告状态"
        align="center"
      >
        <template #default="{ row }">
          <span>{{
            row.auditstatus == 0
              ? "待审核"
              : row.auditstatus == 1
              ? "审核中"
              : row.auditstatus == 2
              ? "退回重审"
              : row.auditstatus == 10
              ? "已审核"
              : ""
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="filtrateList.includes('devname')"
        min-width="81px"
        prop="devname"
        label="设备名称"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('checkTime')"
        prop="checkTime"
        min-width="160px"
        label="检查时间"
        align="center"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          <span>{{
            row.checkTime ? row.checkTime : "----/--/-- --:--:--"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="filtrateList.includes('docname')"
        prop="docname"
        min-width="81px"
        label="检查医师"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('uploadTime')"
        prop="uploadTime"
        min-width="160px"
        label="上传时间"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('analyseDoc')"
        prop="analyseDoc"
        min-width="81px"
        label="分析医师"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('reportTime')"
        prop="reportTime"
        min-width="160px"
        label="报告时间"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('reviewTime')"
        prop="reviewTime"
        min-width="160px"
        label="质控时间"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('mrid')"
        prop="mrid"
        min-width="160px"
        label="病历记录ID"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('devid')"
        prop="devid"
        min-width="102px"
        label="设备SN"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('addr')"
        prop="addr"
        min-width="81px"
        label="销售省份"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column
        v-if="filtrateList.includes('uname')"
        prop="uname"
        min-width="81px"
        label="销售姓名"
        align="center"
        show-overflow-tooltip
      />
    </el-table>
    <el-pagination
      v-model:current-page="pageList.current"
      v-model:page-size="pageList.size"
      :page-sizes="[20, 40, 60, 80]"
      small="small"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageList.total"
      class="pagination-css"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getUltraSoundList } from "@/apis/reportReview";
import { getSubIns, getSubInsAudit } from "@/apis/hospitalManagement";
import areaData from "@/utils/area_value";
import format from "@/utils/format";
import { ElMessage } from "element-plus";
import { getUserOrganNameList } from "@/apis/reportStatistics";
export default {
  data() {
    let _this = this;
    return {
      organNameList: [],
      fullscreenLoading: false,
      json_fields: {
        序号: {
          field: "index",
          callback: (value) => {
            return String(value);
          },
        },
        项目类型: {
          field: "project",
          callback: (value) => {
            return String(value);
          },
        },
        销售省份: {
          field: "addr",
          callback: (value) => {
            return String(value);
          },
        },
        销售姓名: {
          field: "uname",
          callback: (value) => {
            return String(value);
          },
        },
        条码: {
          field: "t_sn",
          callback: (value) => {
            return String(value);
          },
        },
        设备SN: {
          field: "devid",
          callback: (value) => {
            return String(value);
          },
        },
        设备名称: {
          field: "devname",
          callback: (value) => {
            return String(value);
          },
        },
        姓名: {
          field: "name",
          callback: (value) => {
            return String(value);
          },
        },
        性别: {
          field: "sex",
          callback: (value) => {
            return String(value);
          },
        },
        年龄: {
          field: "age",
          callback: (value) => {
            return String(value);
          },
        },
        年龄: {
          field: "age",
          callback: (value) => {
            return String(value);
          },
        },
        检查时间: {
          field: "checkTime",
          callback: (value) => {
            return String(value);
          },
        },
        项目点名称: {
          field: "insname",
          callback: (value) => {
            return String(value);
          },
        },
        检查医师: {
          field: "docname",
          callback: (value) => {
            return String(value);
          },
        },
        上传时间: {
          field: "uploadTime",
          callback: (value) => {
            return String(value);
          },
        },
        分析医师: {
          field: "analyseDoc",
          callback: (value) => {
            return String(value);
          },
        },
        报告时间: {
          field: "reportTime",
          callback: (value) => {
            return String(value);
          },
        },
        审核机构: {
          field: "auditinsname",
          callback: (value) => {
            return String(value);
          },
        },
        审核医师: {
          field: "auditname",
          callback: (value) => {
            return String(value);
          },
        },
        审核时间: {
          field: "audittm",
          callback: (value) => {
            return String(value);
          },
        },
        报告状态: {
          field: "auditText",
          callback: (value) => {
            return String(value);
          },
        },
      },
      userExcelName: "",
      hosProps: {
        lazy: true,
        checkStrictly: true,
        label: "insname",
        value: "inscode",
        lazyLoad(node, resolve) {
          _this.getJunior(node, resolve);
        },
      },
      auditProps: {
        lazy: true,
        checkStrictly: true,
        label: "insname",
        value: "inscode",
        lazyLoad(node, resolve) {
          _this.getAuditJunior(node, resolve);
        },
      },
      typeList: [
        {
          label: "河南村医",
          value: "河南村医",
        },
        {
          label: "慧医",
          value: "慧医",
        },
        {
          label: "筛查",
          value: "高济",
        },
        {
          label: "国药爱心",
          value: "国药爱心",
        },
        {
          label: "新疆百草堂",
          value: "新疆百草堂",
        },
        {
          label: "心血管研究院",
          value: "心血管研究院",
        },
      ],
      reportList: [
        {
          label: "待审核",
          value: "0",
        },
        {
          label: "审核中",
          value: "1",
        },
        {
          label: "退回重审",
          value: "2",
        },
        {
          label: "已审核",
          value: "10",
        },
      ],
      provinceList: areaData,
      projectList: [],
      hospitalList: [],
      ruleform: {
        projectType: "",
        reportTime: [],
        reportType: "",
        province: "",
        sellName: "",
        projectPoint: "",
        auditHospital: "",
      },
      filtrateList: [
        "project",
        "addr",
        "uname",
        "t_sn",
        "devid",
        "devname",
        "name",
        "sex",
        "age",
        "checkTime",
        "insname",
        "docname",
        "uploadTime",
        "analyseDoc",
        "auditstatus",
        "reportTime",
        "auditinsname",
        "auditname",
        "audittm",
        "reviewTime",
        "mrid",
        "auditstatus",
      ],
      tableLoading: false,
      tableData: [],
      pageList: {
        current: 1,
        size: 20,
        total: 0,
      },
    };
  },
  mounted() {
    this.getUserOrganName()
    let reportNonAudit = localStorage.getItem("reportNonAudit");
    if (reportNonAudit) {
      this.filtrateList = JSON.parse(reportNonAudit);
    }
    this.init();
    this.saveCookie();
  },
  methods: {
    getUserOrganName() {
      this.organNameList = []
      getUserOrganNameList({
        uname: this.$store.getters.name,
      }).then((result) => {
        this.organNameList = result.data;
      });
    },
    saveCookie() {
      let reportNonAudit = JSON.stringify(this.filtrateList);
      localStorage.setItem("reportNonAudit", reportNonAudit);
    },
    changeBox() {
      let reportNonAudit = JSON.stringify(this.filtrateList);
      localStorage.setItem("reportNonAudit", reportNonAudit);
    },
    async downloadEx() {
      let inspecSTime = "";
      let inspecETime = "";
      let data = [];
      let projectName = "";
      let auditorName = "";
      // if (this.ruleform.projectPoint && this.ruleform.projectPoint.length > 0) {
      //   projectName = this.ruleform.projectPoint[this.ruleform.projectPoint.length - 1]
      // }
      projectName = this.ruleform.projectPoint
        ? this.ruleform.projectPoint
        : "";
      if (
        this.ruleform.auditHospital &&
        this.ruleform.auditHospital.length > 0
      ) {
        auditorName =
          this.ruleform.auditHospital[this.ruleform.auditHospital.length - 1];
      }
      this.fullscreenLoading = true;
      if (this.ruleform.reportTime && this.ruleform.reportTime.length > 0) {
        inspecSTime = this.ruleform.reportTime[0];
        inspecETime = this.ruleform.reportTime[1];
        this.userExcelName =
          "超声报告非审核类统计表" + inspecSTime + "~" + inspecETime;
        let res = await getUltraSoundList({
          page: 1, // 当前页
          size: 10000, // 每页size
          uname: this.$store.getters.name, // 登录用户
          insname: this.$store.getters.insname, //用户机构名
          inspectionStime: "", // 检查开始时间
          inspectionEtime: "", // 检查结束时间
          uploadStime: "", //上传开始时间
          uploadEtime: "", //上传结束时间
          reportStime: this.ruleform.reportTime
            ? this.ruleform.reportTime[0]
              ? this.ruleform.reportTime[0]
              : ""
            : "", //报告开始时间
          reportEtime: this.ruleform.reportTime
            ? this.ruleform.reportTime[1]
              ? this.ruleform.reportTime[1]
              : ""
            : "", //报告结束时间
          projectName: projectName, //项目点名称
          auditorName: auditorName, //审核机构名称
          auditorDoctor: "", //审核医师
          auditstatus: this.ruleform.reportType, //报告状态
          project: this.ruleform.projectType,
          reportStatus: "noaudit",
        });
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            res.data.forEach((el, index) => {
              let auditText = "";
              el.index = index + 1;
              if (el.auditstatus == 0) {
                auditText = "待审核";
              } else if (el.auditstatus == 1) {
                auditText = "审核中";
              } else if (el.auditstatus == 2) {
                auditText = "退回重审";
              } else if (el.auditstatus == 10) {
                auditText = "已审核";
              }
              el.auditText = auditText;
              if (Number(el.checkTime) > 0) {
                el.checkTime = format(
                  el.checkTime * 1000,
                  "YYYY-MM-DD HH:mm:ss"
                );
                el.checkTime2 = format(el.checkTime * 1000, "YYYY-MM-DD");
              } else {
                el.checkTime = "";
                el.checkTime2 = "";
              }
              el.uploadTime = format(
                el.uploadTime * 1000,
                "YYYY-MM-DD HH:mm:ss"
              );
              el.reportTime = format(
                el.reportTime * 1000,
                "YYYY-MM-DD HH:mm:ss"
              );
              el.ctime2 = format(el.ctime * 1000, "YYYY-MM-DD");
              el.reportTime2 = format(el.reportTime * 1000, "YYYY-MM-DD");
              el.audittm = format(el.audittm * 1000, "YYYY-MM-DD");
            });
            data = res.data;
          }
        }
        this.fullscreenLoading = false;
        return data;
      } else {
        ElMessage({
          message: "请选择报告时间",
          type: "warning",
        });
        this.fullscreenLoading = false;
        return data;
      }
    },
    init() {
      this.getTableData();
    },
    getTableData() {
      this.tableData = [];
      this.tableLoading = true;
      let projectName = "";
      let auditorName = "";
      // if (this.ruleform.projectPoint && this.ruleform.projectPoint.length > 0) {
      //   projectName = this.ruleform.projectPoint[this.ruleform.projectPoint.length - 1]
      // }
      projectName = this.ruleform.projectPoint
        ? this.ruleform.projectPoint
        : "";
      if (
        this.ruleform.auditHospital &&
        this.ruleform.auditHospital.length > 0
      ) {
        auditorName =
          this.ruleform.auditHospital[this.ruleform.auditHospital.length - 1];
      }
      getUltraSoundList({
        page: this.pageList.current, // 当前页
        size: this.pageList.size, // 每页size
        uname: this.$store.getters.name, // 登录用户
        insname: this.$store.getters.insname, //用户机构名
        inspectionStime: "", // 检查开始时间
        inspectionEtime: "", // 检查结束时间
        uploadStime: "", //上传开始时间
        uploadEtime: "", //上传结束时间
        reportStime: this.ruleform.reportTime
          ? this.ruleform.reportTime[0]
            ? this.ruleform.reportTime[0]
            : ""
          : "", //报告开始时间
        reportEtime: this.ruleform.reportTime
          ? this.ruleform.reportTime[1]
            ? this.ruleform.reportTime[1]
            : ""
          : "", //报告结束时间
        projectName: projectName, //项目点名称
        auditorName: auditorName, //审核机构名称
        auditorDoctor: "", //审核医师
        auditstatus: this.ruleform.reportType, //报告状态
        project: this.ruleform.projectType,
        sellname: this.ruleform.sellName, //销售姓名
        reportStatus: "noaudit",
      }).then((res) => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            res.data.forEach((el) => {
              let jsonData = el.json ? JSON.parse(el.json) : "";
              el.checkTime = format(el.checkTime * 1000, "YYYY-MM-DD HH:mm:ss");
              el.uploadTime = format(
                el.uploadTime * 1000,
                "YYYY-MM-DD HH:mm:ss"
              );
              el.reportTime = format(
                el.reportTime * 1000,
                "YYYY-MM-DD HH:mm:ss"
              );
              el.checkTime2 = format(el.checkTime * 1000, "YYYY-MM-DD");
              el.ctime2 = format(el.ctime * 1000, "YYYY-MM-DD");
              el.reportTime2 = format(el.reportTime * 1000, "YYYY-MM-DD");
              el.audittm = format(el.audittm * 1000, "YYYY-MM-DD");
              el.reviewTime = jsonData.reviewDate ? jsonData.reviewDate : "";
              el.mrid = jsonData.mrid ? jsonData.mrid : "";
            });
            this.tableData = res.data;
            this.pageList.total = res.size;
          }
          this.tableLoading = false;
        }
      });
    },
    getJunior(node, resolve) {
      let subins = "";
      if (node.value) {
        subins = node.value;
      }
      getSubIns({
        uname: this.$store.getters.name,
        inscode: this.$store.getters.inscode,
        subins: subins,
      }).then((res) => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            resolve(res.data);
          } else {
            resolve([]);
          }
        } else {
          resolve([]);
        }
      });
    },
    getAuditJunior(node, resolve) {
      let subins = "";
      if (node.value) {
        subins = node.value;
      }
      getSubInsAudit({
        uname: this.$store.getters.name,
        inscode: this.$store.getters.inscode,
        subins: subins,
      }).then((res) => {
        if (res.code == 0) {
          if (res.data && res.data.length > 0) {
            resolve(res.data);
          } else {
            resolve([]);
          }
        } else {
          resolve([]);
        }
      });
    },
    // 搜索
    search() {
      this.pageList.current = 1;
      this.getTableData();
    },
    // 重置
    reset() {
      this.ruleform.projectType = "";
      this.ruleform.reportTime = [];
      this.ruleform.reportType = "";
      this.ruleform.province = "";
      this.ruleform.sellName = "";
      this.ruleform.projectPoint = "";
      this.ruleform.auditHospital = "";
      this.pageList.current = 1;
      this.pageList.size = 20;
      this.getTableData();
    },
    handleSizeChange(val) {
      this.pageList.current = 1;
      this.pageList.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.pageList.current = val;
      this.getTableData();
    },
  },
};
</script>